Smart Buttons
Controls/XML Elements

Manage Collection <ManageCollection>

This control can:

  • Extract a specific element from a collection (minimum number, maximum number, last element, first element).

  • Calculate the number of elements in a collection or average of all numeric elements in the collection (count).

  • Filter from a collection to include only unique elements.

Configuring

You can configure ManageCollection in the Smart Buttons Editor using either the Manage Collection XML Generator or XML.

Configuring with the Smartpoint Buttons XML Generator

To configure with the Smart Buttons XML Generator:

  1. Open the Smart Buttons Editor to create a script.

  2. Click Manage Collection <ManageCollection> to display the Manage Collection Editor.

  3. Configure the attributes.

    These examples of collections of elements are used in the following descriptions:

    • Collection1

      Simple collection: ABC;30;50;80;2;ABC;2;HK90

    • Collection2

      Collection type Value**Key: IBM**49;Mats**80; Cola**36;Trax**390;Mats**7; Cola**36

    • Collection3
      Collection type Value**Key: 2**Lufthansa;1**Austrian;0**Aeroflot;5**AmericanAirlines

    Attribute

    Description

    Variable name

    Mandatory field. Enter the name of that variable that will store the result from the control.

    Action type

    Click the arrow to select the action to perform on the collection.

    The following examples apply to the action descriptions:

    • Collection1
      Simple collection: ABC;30;50;80;2;ABC;2;HK90

    • Collection2

      Collection type Value**Key: IBM**49;Mats**80; Cola**36;Trax**390;Mats**7; Cola**36

    Available action types:

    • Count
      Returns number of elements in the collection. For example, Collection1 returns a count of "8".

    • Last
      Returns the last element in the collection. For example, Collection1 returns "HK90".

    • First
      Returns the first element in the collection. For example, Collection1 returns "ABC".

    • Sum
      Returns the sum of all elements that are numbers. (Text elements are ignored.) For example, Collection1 returns "164" (30+50+80+2+2).

    • Maximum
      Returns the the highest number in the collection. (Text elements are ignored.) For example, Collection1 returns "80".

    • Minimum
      Returns the the highest number in the collection. (Text elements are ignored.) For example, Collection1 returns "2".

    • Average
      Returns the average of all numbers in the collection. (Text elements are ignored.) For example, Collection1 returns "32,8" ((30+50+80+2+2):5).

    • OperateOn
      If the collection is Key**Value type, you may want to operate only on Value or only on Key. For example, to find a maximum number, but only within the Value part of the elements. By default, the complete element is considered.

    Return

    In case of Value**Key collection, select to return back to the variable:

    • ValueKey: All elements to the agent (ValueKey)

    • Value: Only values

    • Keys: Only keys

    Note: @Return works only for Value**Key collections. For Simple collections, it is ignored.

    FilterUnique

    Filters the collection and return only unique elements. In Collection1:

    • Unique elements are: 30;50;80;2;ABC;HK90

    • “ABC” and “2” display twice in the collection and are filtered out.

    Important to remember!

    If you use both @FilterUnique and @ActionType, @FilterUnique always runs first to filter the original collection. @ActionType then runs on the already filtered collection. For example:

    Collection: APPLES;PEARS,KIWI;APPLES

    ActionType:Last

    +

    FilterUnique:Element

    =

    Result: KIWI

    After the first (@FilterUnique) filtration is completed, the last item, APPLES, is filtered out as duplicated, and collection is changed to APPLES;PEARS,KIWI. Then, ActionType filters out the Last element, and last item in the filtered collection is KIWI.

Important!

@ActionType can be used with “Return” and “OperateOn” only as noted.

For example, ActionType:Last and Return can be used together, but ActionType:Count and Return cannot be used together (@Return is ignored).

Configuring with XML

If you want to enter the XML code directly in the Smart Buttons Editor, use the following structure for the XML element.

Copy
<ManageCollection VarName="" ActionType="First" OperateOn="" Return="" FilterUnique="">

Tip! You can add the XML code directly to the editor by dragging and dropping the blue button for this control.

Examples

The following examples use the ManageCollection XML element in the script.

Example 1

Extracts the lowest number from a collection.

The collection is a Simple type and the values are static.

Copy
<ManageCollection VarName="LowestElement" ActionType="Minimum"> 213;10;8788;2902;892;ABC7</ManageCollection>

Because ActionType-Minimum is selected, the control returns the lowest number (10), and ignores elements that are not numbers. In this example, element: ABC7 is text, not a number, because it contains both letters and numbers.

Example 2

Requests the number of unique notepad remarks in a Booking File.

The following script creates a collection of all notepad remarks with GetString control, and then filters unique items (first) and the count of elements in collection(2) with the ManageCollection control.

Copy
<ButtonConf ButtonName="Notepads" Description="" QuickCommand="">
<RunCommand>*NP</RunCommand>
<GetString VarName="AllNotepads"><![CDATA[\d\. (.*) (?:.{2} \d{2}[A-Z]{3} [0-9]{4}Z)]]></GetString>
<ManageCollection VarName="NumberOfUniqueNotepads" ActionType="Count" FilterUnique="Element">[AllNotepads]</ManageCollection>
<ShowMessage>The number of unique notepads in this PNR is: [NumberOfUniqueNotepads]</ShowMessage>
</ButtonConf>

In this example, there are five notepad remarks, but two of the remarks (4 and 5) have the same value. Therefore, the last remark (5) is filtered out and the final number of unique elements in the collection is four.

Example 3

Reads customer name and customer balance from an Excel file (collection type Value**Key) and find display the name of customer with the lowest “customer balance”.

The Excel file:

The script reads the Excel file and selects the customer with the lowest Customer Balance:

Copy
<ButtonConf ButtonName="Manage collection" Description="" QuickCommand="">
<ShowMessage>[CustNumAndCustbalance]</ShowMessage>
<ManageCollection VarName="CustomerWithLowestBalance" ActionType="Minimum" OperateOn="Key" Return="Value">[CustNumAndCustbalance]</ManageCollection>
<ShowMessage>[CustomerWithLowestBalance]</ShowMessage>
</ButtonConf>

First, the script reads the Excel file with ReadFromExcel XML element, then shows the collection in a message box with ShowMessage XML element.

Because this collection is a Value**Key collection, each element of the collection contains two parts:

  • Value - Customer Name

  • Key - Customer Balance.

Next, the ManageCollection element determines which part to operate on (@OperateOn). To operate only on the Customer Balance (calculate the minimum Customer Balance), OperateOn="Key" is used. In this control, to return the Customer Name (Value) with the lowest balance, instead of the amount of the Customer Balance, Return="Value" is selected.

The last control is ShowMessage, which displays the final result - the name of the customer with the lowest customer balance: